<template>
  <view v-if="visible" class="modal-overlay" @click="closeModal">
    <view class="modal-content" @click.stop>
      <view class="modal-header">
        <text class="modal-title">{{ title }}</text>
        <button class="close-btn" @click="closeModal">
          <text class="close-icon">×</text>
        </button>
      </view>
      
      <view class="modal-body">
        <slot></slot>
      </view>
    </view>
  </view>
</template>

<script>
export default {
  name: 'GameModal',
  props: {
    visible: {
      type: Boolean,
      default: false
    },
    title: {
      type: String,
      default: '弹窗'
    }
  },
  methods: {
    closeModal() {
      this.$emit('close')
    }
  }
}
</script>

<style scoped>
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4rpx);
}

.modal-content {
  background: #ffffff;
  border-radius: 16rpx;
  width: 90%;
  max-width: 600rpx;
  max-height: 80%;
  overflow: hidden;
  border: 1rpx solid rgba(0, 0, 0, 0.1);
  box-shadow: 0 8rpx 24rpx rgba(0, 0, 0, 0.2);
  animation: modalSlideIn 0.3s ease-out;
}

@keyframes modalSlideIn {
  from {
    opacity: 0;
    transform: scale(0.9) translateY(-20rpx);
  }
  to {
    opacity: 1;
    transform: scale(1) translateY(0);
  }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20rpx;
  border-bottom: 1rpx solid rgba(0, 0, 0, 0.1);
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
}

.modal-title {
  font-size: 20rpx;
  font-weight: bold;
  color: white;
}

.close-btn {
  width: 32rpx;
  height: 32rpx;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.3s ease;
}

.close-btn:active {
  transform: scale(0.95);
  background: rgba(255, 255, 255, 0.3);
}

.close-icon {
  font-size: 18rpx;
  color: white;
  font-weight: bold;
}

.modal-body {
  padding: 20rpx;
  max-height: 400rpx;
  overflow-y: auto;
}

/* 移动端优化 */
@media (max-width: 768rpx) {
  .modal-content {
    width: 95%;
    max-height: 85%;
  }
  
  .modal-header {
    padding: 16rpx;
  }
  
  .modal-title {
    font-size: 18rpx;
  }
  
  .close-btn {
    width: 28rpx;
    height: 28rpx;
  }
  
  .close-icon {
    font-size: 16rpx;
  }
  
  .modal-body {
    padding: 16rpx;
    max-height: 350rpx;
  }
}
</style>

